//
//  FaFangZiYuanCell.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/25.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "FaFangZiYuanCell.h"

@implementation FaFangZiYuanCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initSubView];
        [self layout];
    }
    return self;
}
- (void)initSubView{
    CGFloat W = self.frame.size.width/8;
    CGFloat X = W-15;
    for (int i = 0; i<8; i++){
        if (i == 0) {
            UILabel *label = [[UILabel alloc]init];
            label.frame = CGRectMake(X*i,0,X,44);
            label.numberOfLines = 0;
            label.textAlignment = 1;
            label.tag = 30+i;
            label.font = [UIFont systemFontOfSize:14];
            label.textColor = [UIColor darkGrayColor];
            [self addSubview:label];
        }else if (i<4) {
            UILabel *label = [[UILabel alloc]init];
            label.frame = CGRectMake(W*(i-1)+X,0,W,44);
            label.numberOfLines = 0;
            label.textAlignment = 1;
            label.tag = 30+i;
            label.font = [UIFont systemFontOfSize:14];
            label.textColor = [UIColor darkGrayColor];
            [self addSubview:label];
        }else if (i==4){
            UILabel *label = [[UILabel alloc]init];
            label.frame = CGRectMake(W*3+X,0,X,44);
            label.numberOfLines = 0;
            label.textAlignment = 1;
            label.tag = 30+i;
            label.font = [UIFont systemFontOfSize:14];
            label.textColor = [UIColor darkGrayColor];
            [self addSubview:label];
        }else if (i == 5) {
            UILabel *label = [[UILabel alloc]init];
            label.frame = CGRectMake(W*3+X*2,0,X+40,44);
            label.numberOfLines = 0;
            label.textAlignment = 1;
            label.tag = 30+i;
            label.font = [UIFont systemFontOfSize:14];
            label.textColor = [UIColor darkGrayColor];
            [self addSubview:label];
        }else if (i == 6){
            self.xuanZeZiYuanButton.frame = CGRectMake(W*4+X*2+40+X*(i-6)+W/2-8.5,44/2-4.5,17,9);
            [self addSubview:self.xuanZeZiYuanButton];
        }else{
            self.quXiaoZiYuanButton.frame = CGRectMake(W*4+X*2+40+X*(i-6)+W/2-7.5,44/2-7.5,15,15);
            [self addSubview:self.quXiaoZiYuanButton];
        }

    }
}

- (void)reloadViewLayout{
    CGFloat W = self.frame.size.width/8;
    CGFloat X = W-10;
    for (int i = 0; i<8; i++){
        if (i == 0) {
            UILabel *label = (UILabel *)[self viewWithTag:30+i];
            label.frame = CGRectMake(X*i,0,X,44);
            label.text = _dataArray[i];
        }else if (i<4) {
            UILabel *label = (UILabel *)[self viewWithTag:30+i];
            label.frame = CGRectMake(W*(i-1)+X,0,W,44);
            label.text = _dataArray[i];
        }else if (i==4){
            UILabel *label = (UILabel *)[self viewWithTag:30+i];
            label.frame = CGRectMake(W*3+X,0,X,44);
            label.text = _dataArray[i];
        }else if (i == 5) {
            UILabel *label = (UILabel *)[self viewWithTag:30+i];
            label.frame = CGRectMake(W*3+X*2,0,X+40,44);
            label.text = _dataArray[i];
        }else{
            if (i == 6) {
                self.xuanZeZiYuanButton.frame = CGRectMake(W*4+X*2+40+X*(i-6)+X/2-8.5,44/2-4.5,17,9);
            }else{
                self.quXiaoZiYuanButton.frame = CGRectMake(W*4+X*2+40+X*(i-6)+X/2-7.5,44/2-7.5,15,15);
            }
        }
    }
}
- (void)layout{
    
}
- (UIButton *)xuanZeZiYuanButton{
    if (!_xuanZeZiYuanButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"arrow_down"] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        [button setTitleColor:SELECTEDCOLOR forState:0];
        [button addTarget:self action:@selector(xuanZeZiYuanButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        _xuanZeZiYuanButton = button;
    }
    return _xuanZeZiYuanButton;
}
- (void)xuanZeZiYuanButtonClick:(UIButton *)sender{
    self.resourceBloxk(self.indexPath);
}
- (UIButton *)quXiaoZiYuanButton{
    if (!_quXiaoZiYuanButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"fudao_close"] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        [button setTitleColor:SELECTEDCOLOR forState:0];
        [button addTarget:self action:@selector(quXiaoZiYuanButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        _quXiaoZiYuanButton = button;
    }
    return _quXiaoZiYuanButton;
}
- (void)quXiaoZiYuanButtonClick:(UIButton *)sender{
    self.removeBlock(self.indexPath);
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
